package com.ruding.disruptor.init;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.WorkHandler;

public class CountEventHandler implements EventHandler<SeriesDataEvent> {

    private Logger logger = LoggerFactory.getLogger(CountEventHandler.class);
    
    private static Map<String, AtomicInteger> CountMap = new ConcurrentHashMap<>();

//    @Autowired
//    private DeviceInfoService deviceInfoService;

	@Override
	public void onEvent(SeriesDataEvent event, long sequence, boolean endOfBatch) throws Exception {
//		String batchId = event.getValue().getBatchId();
//		int size = event.getValue().getSize();
//		if(CountMap.containsKey(batchId)){
//			AtomicInteger i= CountMap.get(batchId);
//			i.incrementAndGet();
//			if(i.get()<size){
//				CountMap.put(batchId, i);
//			}else{
//				CountMap.remove(batchId);
//				logger.info(batchId+"处理完成.....");
//			}
//		}else{
//			CountMap.put(batchId, new AtomicInteger(1));
//		}
//		logger.info("sequence:"+sequence+" endOfBatch:" +endOfBatch+ " data:"+JSON.toJSONString(event));
	}

}
